﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Visa.DB;
using System.Data;

namespace Visa.Service
{
    public class YkienkhachanhService
    {
        private VisaEntities db = new VisaEntities();

        public int addOrUpdateNews(Ykienkhachang entity)
        {
            db.Entry(entity).State = entity.Id == -1 ? EntityState.Added : EntityState.Modified;
            db.SaveChanges();
            return entity.Id;
        }

        public void addOrUpdateNewsStaus(int id, bool  entity)
        {
            var c = db.Ykienkhachangs.SingleOrDefault(l => l.Id == id);
            c.Status = entity;
            db.SaveChanges();
        }

        public void Delete(int id)
        {
            var c = db.Ykienkhachangs.SingleOrDefault(l => l.Id == id);
            db.Ykienkhachangs.Remove(c);
            db.SaveChanges();
        }

        public Ykienkhachang GetById(int id)
        {
            try
            {
                return db.Ykienkhachangs.SingleOrDefault(l => l.Id == id);
            }
            catch { return null; }
        }


        public bool checkEmail(string email)
        {
            try
            {
                var c = db.Ykienkhachangs.SingleOrDefault(l => l.Email == email);
                if (c != null) return true;
                else return false;
            }
            catch { return false; }
        }

        public List<Ykienkhachang> GetAll()
        {
            try
            {
                return db.Ykienkhachangs.ToList();
            }
            catch { return null; }
        }
    }
}
